package com.meilishuo.message.entity.common;
import java.util.ArrayList;
import java.util.List;

/**
 * 
 * The result of a paging query.
 * 
 * @author binbinshen
 *
 * @param <T>
 */
public class PageResult<T> {
	private static final int PAGESIZE = 10;
	// The current page number
	private int pageNumber = 1;
	// The total pages of all result
	private int totalPages;
	// The total rows of all result
	// The page size, means the max rows in one page
	private int pageSize = PAGESIZE;
	private int totalRows;
	// The result rows in this page
	private List<T> rows = new ArrayList<T>();

	public int getPageNumber() {
		return pageNumber;
	}

	public void setPageNumber(int pageNumber) {
		this.pageNumber = pageNumber;
	}

	public int getTotalPages() {
		return totalPages;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(int totalRows) {
		if ((totalRows % pageSize) == 0) {
			totalPages = totalRows / pageSize;
		} else {
			totalPages = totalRows / pageSize + 1;
		}
		if (totalRows == 0) {
			totalPages = 1;
		}
		this.totalRows = totalRows;
	}

	public List<T> getRows() {
		return rows;
	}

	public void setRows(List<T> rows) {
		this.rows = rows;
	}
}
